﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="pgAdmLicencias.aspx.cs" Inherits="EGuayas.Web.Licenciamiento.pgAdmLicencias" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title><link  href="~/Resources/css/Style.css"  rel="stylesheet" /><!-- Load Ext JS -->
     <script src="../../Resources/js/Global.js"></script>

</head>
<body>
    <form runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server"></ext:ResourceManager>
    <ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout">
        <Items>
            <ext:Panel ID="Panel1" runat="server" Region="North" BodyPadding="6" Header="False" ButtonAlign="Center" >
                <Items>
                    <ext:Panel ID="panC1" runat="server" Layout="ColumnLayout" Border="false">
                        <Items>
                            <ext:Panel ID="panC1Col1" runat="server" ColumnWidth=".33" Border="false">
                                <Items>
                                    <ext:ComboBox ID="cbbProvincia" runat="server" FieldLabel="Provincia" ValueField="Id" DisplayField="Nombre">
                                        <Store>
                                            <ext:Store runat="server" ID="stoProvincia">
                                                <Model>
                                                    <ext:Model ID="Model1" runat="server" IDProperty="Id">
                                                        <Fields>
                                                            <ext:ModelField Name="Id"></ext:ModelField>
                                                            <ext:ModelField Name="Nombre"></ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:Store>
                                        </Store>
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                        </Triggers>
                                        <Listeners>
                                            <Select Handler="this.getTrigger(0).show();" />
                                            <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                            <TriggerClick Handler="if (index == 0) { 
                                           this.clearValue(); 
                                           this.getTrigger(0).hide();
                                       }" />
                                        </Listeners>
                                        <DirectEvents>
                                            <Select OnEvent="cbbProvincia_Select">
                                                <ExtraParams>
                                                    <ext:Parameter Name="Id" Value="#{cbbProvincia}.getValue()" Mode="Raw"/>
                                                </ExtraParams>
                                                <EventMask ShowMask="True"></EventMask>
                                            </Select>
                                        </DirectEvents>
                                    </ext:ComboBox>
                                    <ext:TextField ID="txtCodigo" runat="server" FieldLabel="Código"></ext:TextField>
                                    <ext:DateField 
                                                    ID="dfFechaInicio" 
                                                    Name="FechaInicio"
                                                    runat="server" 
                                                    FieldLabel="Fecha Inicio" 
                                                    Vtype="daterange" 
                                                    EndDateField="dfFechaLimite"
                                                    EnableKeyEvents="true">
                                    </ext:DateField>
                                </Items>
                            </ext:Panel>
                            <ext:Panel ID="panC1Col2" runat="server" ColumnWidth=".33" Border="false">
                                <Items>
                                    <ext:ComboBox ID="cbbCanton" runat="server" FieldLabel="Cantón" ValueField="Id" DisplayField="Nombre">
                                        <Store>
                                            <ext:Store runat="server" ID="stoCanton">
                                                <Model>
                                                    <ext:Model ID="Model3" runat="server" IDProperty="Id">
                                                        <Fields>
                                                            <ext:ModelField Name="Id"></ext:ModelField>
                                                            <ext:ModelField Name="Nombre"></ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:Store>
                                        </Store>
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                        </Triggers>
                                        <Listeners>
                                            <Select Handler="this.getTrigger(0).show();" />
                                            <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                            <TriggerClick Handler="if (index == 0) { 
                                           this.clearValue(); 
                                           this.getTrigger(0).hide();
                                       }" />
                                        </Listeners>
                                        <DirectEvents>
                                            <Select OnEvent="cbbCanton_Select">
                                                <ExtraParams>
                                                    <ext:Parameter Name="Id" Value="#{cbbCanton}.getValue()" Mode="Raw"/>
                                                </ExtraParams>
                                                <EventMask ShowMask="True"></EventMask>
                                            </Select>
                                        </DirectEvents>
                                    </ext:ComboBox>
                                    <ext:TextField ID="txtNombre" runat="server" FieldLabel="Nombre"></ext:TextField>
                                    <ext:DateField 
                                                    ID="dfFechaLimite"
                                                    Name="FechaFin"
                                                    runat="server"                                                   
                                                    FieldLabel="Fecha Fin"
                                                    Vtype="daterange"
                                                    StartDateField="dfFechaInicio"
                                                    EnableKeyEvents="true">
                                    </ext:DateField>
                                </Items>
                            </ext:Panel>
                            <ext:Panel ID="panC1Col3" runat="server" ColumnWidth=".33" Border="false">
                                <Items>
                                    <ext:ComboBox ID="cbbParroquia" runat="server" FieldLabel="Parroquia" ValueField="Id" DisplayField="Nombre">
                                        <Store>
                                            <ext:Store runat="server" ID="stoParroquia">
                                                <Model>
                                                    <ext:Model ID="Model4" runat="server" IDProperty="Id">
                                                        <Fields>
                                                            <ext:ModelField Name="Id"></ext:ModelField>
                                                            <ext:ModelField Name="Nombre"></ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:Store>
                                        </Store>
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                        </Triggers>
                                        <Listeners>
                                            <Select Handler="this.getTrigger(0).show();" />
                                            <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                            <TriggerClick Handler="if (index == 0) { 
                                           this.clearValue(); 
                                           this.getTrigger(0).hide();
                                       }" />
                                        </Listeners>
                                    </ext:ComboBox>
                                </Items>
                            </ext:Panel>
                        </Items>
                    </ext:Panel>
                </Items>
                <Buttons>
                    <ext:Button runat="server" ID="btnBuscarExpedientesLic" Text="Buscar">
                        <DirectEvents>
                            <Click OnEvent="btnBuscarExpedientesLic_Click">
                                <ExtraParams>
                                    <ext:Parameter Name="Codigo" Value="#{txtCodigo}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="Nombre" Value="#{txtNombre}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="ProvinciaId" Value="#{cbbProvincia}.getValue()==null?'':#{cbbProvincia}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="CantonId" Value="#{cbbCanton}.getValue()==null?'':#{cbbCanton}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="ParroquiaId" Value="#{cbbParroquia}.getValue()==null?'':#{cbbParroquia}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="FechaDesde" Value="#{dfFechaInicio}.getValue()==null?'':#{dfFechaInicio}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="FechaHasta" Value="#{dfFechaLimite}.getValue()==null?'':#{dfFechaLimite}.getValue()" Mode="Raw"/>
                                </ExtraParams>
                                <EventMask ShowMask="True"></EventMask>
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:Panel>
            <ext:Hidden Text="" ID="hdRol"  runat="server"></ext:Hidden>    
            <ext:GridPanel runat="server" ID="gpnLicencias" Title="Expedientes para Licencias y Certificados Ambientales"
                Region="Center" >
                <Store>
                    <ext:Store runat="server" ID="stoExpedienteLic">
                        <Model>
                    <ext:Model runat="server" IDProperty="Id" >
                        <Fields>
                            <ext:ModelField Name="Id"/>
                            <ext:ModelField Name="ExpedienteId"/>
                            <ext:ModelField Name="Nombre"/>
                            <ext:ModelField Name="Codigo"/>
                            <ext:ModelField Name="Descripcion"/>
                            <ext:ModelField Name="Estado"/>
                            <ext:ModelField Name="Fase"/>
                            
                            <ext:ModelField Name="Tipo"/>
                            <ext:ModelField Name="Categoria"/>
                            <ext:ModelField Name="FechaCreacion" Type="Date"/>
                            <ext:ModelField Name="Provincia"/>
                            <ext:ModelField Name="Canton"/>
                            <ext:ModelField Name="Parroquia"/>
                            <ext:ModelField Name="Direccion"/>
                            <ext:ModelField Name="PromotorIdentificacion"/>
                            <ext:ModelField Name="PromotorNombre"/>
                            <ext:ModelField Name="PromotorEmpresa"/>
                            <ext:ModelField Name="PromotorDireccion"/>
                            <ext:ModelField Name="Ruc"/>
                            <ext:ModelField Name="Telefono"/>
                            <ext:ModelField Name="Celular"/>
                            <ext:ModelField Name="Fax"/>
                            <ext:ModelField Name="Consultor"/>
                            <ext:ModelField Name="ConsultorId"/>
                            <ext:ModelField Name="Ubicacion"/>
                            <ext:ModelField Name="CategoriaExpediente"/>
                        </Fields>
                    </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel>
                    <Columns>
                        <ext:Column runat="server" Text="Nombre" Flex="1" DataIndex="Nombre" />
                        <ext:Column runat="server" Text="Código" DataIndex="Codigo" Width="120" />
                        <ext:Column runat="server" Text="Descripción" DataIndex="Descripcion" Width="150" />
                        <ext:Column runat="server" Text="Estado" DataIndex="Estado" Width="80" />
                        <ext:Column runat="server" Text="Fase" DataIndex="Fase" Width="80" />
                        <ext:Column runat="server" Text="Ubicación" DataIndex="Ubicacion" Width="150" />
                        <ext:Column runat="server" Text="Dirección" DataIndex="Direccion" Width="150" />
                        <ext:CommandColumn runat="server" Width="80" >
                            <Commands>
                            <ext:GridCommand Icon="TableGo" CommandName="VerProceso">
                                <ToolTip Text="Ver proceso de licenciamiento" />
                            </ext:GridCommand>
                            <ext:CommandSeparator />
                        </Commands>
                            <DirectEvents>
                                <Command OnEvent="gpnLicencias_Command" Success="pgFnAdmin.LinkExpediente(record);">
                                    <ExtraParams>
                                        <ext:Parameter Name="Id" Value="record.data.Id" Mode="Raw"/>
                                        <ext:Parameter Name="ExpedienteId" Value="record.data.ExpedienteId" Mode="Raw"/>
                                    </ExtraParams>
                                </Command>
                            </DirectEvents>
                            <%--<Listeners>
                                <Command Handler="AppGlobalJs.mostrarVentanaUrl('pgContentLicencia.aspx?eli_id='+record.data.Id,'Fases');"></Command>
                            </Listeners>--%>
                        </ext:CommandColumn>
                        <ext:CommandColumn ID="CommandColumn1" runat="server" Width="80" >
                            <Commands>
                                <ext:GridCommand Icon="PrinterConnect" CommandName="VerXml">
                                    <ToolTip Text="Imprimir expediente licenciamiento" />
                                </ext:GridCommand>
                                <ext:CommandSeparator />
                            </Commands>
                            <Listeners>
                                <Command Handler="AppGlobalJs.mostrarVentanaUrl('pgDetailXml.aspx?id='+record.data.ExpedienteId,record.data.Nombre);"></Command>
                            </Listeners>
                           <PrepareToolbar Fn="pgFnAdmin.PrepareExp" />
                        </ext:CommandColumn>
                         <ext:Column ID="Column13" runat="server"  Width="70" Align="Right" RightCommandAlign="false"  >
                                        <Commands>
                                            <ext:ImageCommand CommandName="CmdDocAsoc" Icon="PageWhiteCopy"  ToolTip-Text="Ver documentos de expedientes"/>                                                           
                                        </Commands>
                                            <PrepareCommand Fn="pgFnAdmin.PrepareDocAsociados" />
                                        <Listeners> 
                                                <Command Handler="AppGlobalJs.mostrarVentanaUrl('pgDocGlobalLicencias.aspx?Id='+record.data.ExpedienteId,record.data.Nombre);" />                                                         
                                        </Listeners>
                                    </ext:Column>  

                        <%--      
                        <ext:CommandColumn ID="CommandColumn2" runat="server" Width="80" >
                            <Commands>
                                <ext:GridCommand Icon="ApplicationViewGallery" CommandName="VerDocExp">
                                    <ToolTip Text="Documentos expediente licenciamiento" />
                                </ext:GridCommand>
                                <ext:CommandSeparator />
                            </Commands>
                            <Listeners>
                                <Command Handler="AppGlobalJs.mostrarVentanaUrl('pgDocGlobalLicencias.aspx?ExpedienteLicId='+record.data.Id,record.data.Nombre);"></Command>
                            </Listeners>
                           
                        </ext:CommandColumn>
                        --%>
                    </Columns>
                </ColumnModel>
                <View>
                    <ext:GridView ID="GridView1" runat="server" StripeRows="true" />                   
                </View>
                <BottomBar>
                        <ext:PagingToolbar ID="PagingToolbar1" runat="server">
                        <Items>
                            <ext:Label ID="Label1" runat="server" Text="Filas por página:" />
                            <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" Width="10" />
                            <ext:ComboBox ID="ComboBox1" runat="server" Width="80">
                                <Items>
                                    <ext:ListItem Text="5" />
                                    <ext:ListItem Text="10" />
                                    <ext:ListItem Text="15" />
                                    <ext:ListItem Text="20" />
                                    <ext:ListItem Text="25" />
                                    <ext:ListItem Text="30" />
                                    <ext:ListItem Text="35" />
                                    <ext:ListItem Text="40" />
                                    <ext:ListItem Text="45" />
                                    <ext:ListItem Text="50" />
                                </Items>
                                <SelectedItems>
                                    <ext:ListItem Value="10" />
                                </SelectedItems>
                                <Listeners>
                                    <Select Handler="#{gpnLicencias}.store.pageSize = parseInt(this.getValue(), 10); #{gpnLicencias}.store.load();" />
                                </Listeners>
                            </ext:ComboBox>
                        </Items>
                  
                    </ext:PagingToolbar>
                </BottomBar> 
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
    </form>
     <ext:XScript ID="XScript1" runat="server">
        <script type="text/javascript">
            var pgFnAdmin = new Object();
            //Cerrar ventana creada
            pgFnAdmin.BeforeClose = function (win, namewin) {
                try {
                    Ext.Msg.confirm('Aviso', 'Desea cerrar ventana <b>Licenciamiento de ' + namewin + '</b>?', function (btn) {
                        if (btn == 'yes') {
                            win.forceHide();
                            return true;
                        }
                    });
                    return false;
                } catch (jsbug) {
                    AppGlobalJs.showBug("pgFnAdmin.BeforeClose :" + jsbug)
                }
            };
            pgFnAdmin.LinkExpediente = function (record) {
                pgFnAdmin.winUrl = AppGlobalJs.mostrarVentanaUrl('pgContentLicencia.aspx?eli_id=' + record.data.Id, record.data.Nombre);
                pgFnAdmin.winUrl.addListener('close', function (el) {el.destroy(); });
                pgFnAdmin.winUrl.addListener('beforehide', function (el) { return pgFnAdmin.BeforeClose(el, record.data.Nombre); });
            };
            //Mostrar boton imprimir solo caso de expediente con ficha
            pgFnAdmin.PrepareExp = function (grid, toolbar, rowIndex, record) {
                try
                {
                    switch (record.get("CategoriaExpediente"))
                    {
                        case "c1":
                        case "c2":
                        case "c3":
                        toolbar.items.getAt(0).hide();
                        break;
                   
                    }
                } catch (jsbug) 
                {
                    AppGlobalJs.showBug(" pgFnAdmin.PrepareExp : " + jsbug);
                }
            };
            pgFnAdmin.PrepareDocAsociados = function (grid, command, record, row) {
                try
                {
                    if (command.command == 'CmdDocAsoc')
                    {
                      
                        var rolCode=#{hdRol}.getValue();
                        if (rolCode != 'PROMOTOR') {
                           
                            command.hidden = false;
                            command.hideMode = 'visibility';
                        }
                        else
                        {
                            command.hidden = true;
                            command.hideMode = 'display';
                        }


                    }

                } catch (jsbug) {
                    AppGlobalJs.showBug("pgFnAdmin.PrepareDocAsociados : " + jsbug);
                }
            };
 </script>
    </ext:XScript>   
</body>
</html>
